home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / mAz Lite 1.0 / particle.wdl < prev    next >
Encoding:
Text File  |  2003-03-17  |  8.4 KB  |  365 lines

  1. // Template file v5.202 (02/20/02)
  2. ////////////////////////////////////////////////////////////////////////
  3. // File: particle.wdl
  4. //        WDL prefabs for particle effects
  5. ////////////////////////////////////////////////////////////////////////
  6. /////////////////////////////////////////////////////////////////////////
  7. //
  8. /////////////////////////////////////////////////////////////////////////
  9.  
  10.  
  11. // Some common definitions
  12.  
  13. // bitmap used for sparks
  14. BMAP spark_map,<particle.pcx>;
  15. // bitmap used for smoke
  16. BMAP smoke_map, <blitz.pcx>;
  17.  
  18. var scatter_color[3] = 250, 250, 250;
  19. var scatter_range[3] = -100, -245, -245;
  20. var scatter_lifetime    = 50;
  21. var scatter_size = 100; }
  22. var scatter_gravity = 0.25;
  23. var scatter_spread = 6;
  24. /////////////////////////////////////////////////////////////////////////
  25. //SYNONYM scatter_map { TYPE BMAP; DEFAULT spark_map; }
  26. bmap* scatter_map = spark_map;
  27. var particle_pos[3];
  28. var particle_speed[3];
  29. var scatter_speed[3] = 0, 0, 0;
  30.  
  31. /////////////////////////////////////////////////////////////////////////
  32. // The particle_fade action lets a particle fade away
  33.  
  34. var fade_lifetime    = 8;
  35. var fade_color[3] = 255, 200, 0;
  36. var fade_targetcolor[3] = 128, 128, 128;
  37.  
  38. function particle_fade()
  39. {
  40.     if(MY_AGE == 0)
  41.     {    // just born?
  42.         MY_SIZE = 100;
  43.         MY_SPEED.X = RANDOM(2)-1;
  44.         MY_SPEED.Y = RANDOM(2)-1;
  45.         MY_SPEED.Z = RANDOM(2)-1;
  46.         MY_COLOR.RED = fade_color.RED;
  47.         MY_COLOR.GREEN = fade_color.GREEN;
  48.         MY_COLOR.BLUE = fade_color.BLUE;
  49.     }
  50.     else
  51.     {
  52.         MY_COLOR.RED += (fade_targetcolor.RED - MY_COLOR.RED)*0.2;
  53.         MY_COLOR.GREEN += (fade_targetcolor.GREEN - MY_COLOR.GREEN)*0.2;
  54.         MY_COLOR.BLUE += (fade_targetcolor.BLUE - MY_COLOR.BLUE)*0.2;
  55.  
  56.         if(MY_AGE > fade_lifetime) { MY_ACTION = NULL; }
  57.     }
  58. }
  59. /////////////////////////////////////////////////////////////////////////
  60. // The particle_tumble action lets a particle tumble around
  61. // for 0.5 seconds, then disappear.
  62.  
  63. var tumble_lifetime = 8;
  64.  
  65. function particle_tumble()
  66. {
  67.     if(MY_AGE == 0)
  68.     {    // just born?
  69.         MY_SPEED.X = RANDOM(0.3)-0.15;
  70.         MY_SPEED.Y = RANDOM(0.3)-0.15;
  71.         MY_SPEED.Z = RANDOM(0.3)-0.15;
  72.  
  73.         MY_SIZE = 30;
  74.         MY_COLOR.RED = scatter_color.RED * 0.75;
  75.         MY_COLOR.GREEN = scatter_color.GREEN * 0.3;
  76.         MY_COLOR.BLUE = scatter_color.BLUE * 0.3;
  77.     }
  78.     if(MY_AGE > tumble_lifetime)
  79.     {
  80.         MY_ACTION = NULL;
  81.     }
  82. }
  83.  
  84. /////////////////////////////////////////////////////////////////////////
  85. // The particle_scatter action will scatter particles in all directions,
  86. // then let them fall to the ground.
  87. //
  88. function particle_scatter()
  89. {
  90.     // just born?
  91.     if(MY_AGE == 0)
  92.     {
  93.         MY_SPEED.X = scatter_speed.X + RANDOM(scatter_spread) - (scatter_spread/2);
  94.         MY_SPEED.Y = scatter_speed.Y + RANDOM(scatter_spread) - (scatter_spread/2);
  95.         MY_SPEED.Z = scatter_speed.Z + RANDOM(scatter_spread) - (scatter_spread/2);
  96.  
  97.         MY_SIZE = scatter_size;
  98.         MY_COLOR.RED = scatter_color.RED;
  99.         MY_COLOR.GREEN = scatter_color.GREEN;
  100.         MY_COLOR.BLUE = scatter_color.BLUE;
  101.         MY_MAP = scatter_map;
  102.         MY_FLARE = ON;
  103.         return;
  104.     }
  105.     // Add gravity
  106.     MY_SPEED.Z -= scatter_gravity;
  107.     // Maybe add random term to age
  108.     //    MY_AGE += RANDOM(0.05);
  109.  
  110.     if(MY_AGE >= scatter_lifetime)
  111.     {
  112.         MY_ACTION = NULL;
  113.     }
  114. }
  115.  
  116. // The same, but with a particle trace behind
  117. function particle_traces()
  118. {
  119.     particle_scatter();
  120.     // A particle itself may emit further particles
  121.     emit(1,MY_POS,particle_tumble);
  122. }
  123.  
  124. // The same, but with a color range
  125. function particle_range()
  126. {
  127.     particle_scatter();
  128.  
  129.     if(MY_AGE > 0)
  130.     {
  131.         MY_COLOR.RED += scatter_range.RED*MY_AGE/scatter_lifetime;
  132.         MY_COLOR.GREEN += scatter_range.GREEN*MY_AGE/scatter_lifetime;
  133.         MY_COLOR.BLUE += scatter_range.BLUE*MY_AGE/scatter_lifetime;
  134.     }
  135. }
  136.  
  137. // The same, but emits a sphere, with color range
  138. function particle_sphere()
  139. {
  140.     particle_scatter();
  141.     if(MY_AGE == 0)
  142.     {
  143.         vec_normalize(MY_SPEED,scatter_spread);
  144.     }
  145.     else
  146.     {
  147.         MY_COLOR.RED += scatter_range.RED*MY_AGE/scatter_lifetime;
  148.         MY_COLOR.GREEN += scatter_range.GREEN*MY_AGE/scatter_lifetime;
  149.         MY_COLOR.BLUE += scatter_range.BLUE*MY_AGE/scatter_lifetime;
  150.     }
  151. }
  152.  
  153. // This action may be called to initalize the scattering
  154. //
  155. function scatter_init()
  156. {
  157.     vec_set(particle_pos,MY.X);
  158.     vec_set(scatter_speed,NULLVECTOR); // no offset here!
  159. }
  160.  
  161.  
  162. /////////////////////////////////////////////////////////////////////////
  163. // The particle_shot action lets a particle fly in shot_speed
  164. // direction for 2 seconds, then disappear.
  165.  
  166. var shot_lifetime    = 32;
  167. var shot_speed;
  168.  
  169. function particle_shot()
  170. {
  171.     if(MY_AGE == 0)
  172.     {    // just born?
  173.         MY_SPEED.X = shot_speed.X;
  174.         MY_SPEED.Y = shot_speed.Y;
  175.         MY_SPEED.Z = shot_speed.Z;
  176.         MY_SIZE = 100;
  177.         MY_COLOR.RED = 255;
  178.         MY_COLOR.GREEN = 0;
  179.         MY_COLOR.BLUE = 200;
  180.     }
  181.     if(MY_AGE > shot_lifetime)
  182.     {
  183.         MY_ACTION = NULL;
  184.     }
  185. }
  186.  
  187. /////////////////////////////////////////////////////////////////
  188. var rain_mode = 0;
  189. var rain_pos;
  190. var rain_rate = 20;    // snowflakes per second
  191. var rain_counter;
  192.  
  193. // start snowfall around the player
  194. // original idea by Harald Schmidt
  195. function snowfall()
  196. {
  197.     if(player == NULL) { END; }
  198.  
  199.     rain_mode = 1;
  200.     while(rain_mode > 0)
  201.     {
  202.         // all snowflakes will start 50 quants above the player
  203.         rain_pos.Z = player.Z + player.MAX_Z + 50;
  204.  
  205.         //    depending on the frame rate, create several snow flakes at the same time
  206.         rain_counter = rain_rate * TIME;
  207.         while(rain_counter > 0)
  208.         {
  209.             // place snowflake somewhere near the player
  210.             rain_pos.X = player.X + RANDOM(500) - 250;
  211.             rain_pos.Y = player.Y + RANDOM(500) - 250;
  212.             // now create one flake (emit 1) at this position
  213.             emit(1,rain_pos,particle_rain);
  214.             rain_counter -= 1;
  215.         }
  216.         wait(1);
  217.     }
  218. }
  219.  
  220. function particle_rain()
  221. {
  222. // just born?
  223.     if(MY_AGE == 0)
  224.     {  // this simple snow should do nothing more than fall to earth
  225.         MY_SPEED.X = 0;
  226.         MY_SPEED.Y = 0;
  227.         MY_SPEED.Z = -2; // experiment with this value
  228.  
  229. // Set the size and colour you want (or maybe a bitmap)
  230.         MY_SIZE = 100;
  231.         MY_COLOR.RED = 255;
  232.         MY_COLOR.GREEN = 255;
  233.         MY_COLOR.BLUE = 255;
  234.  
  235. //        my_map = spark_map;
  236. //        my_transparent = on;
  237.         END;
  238.     }
  239.  
  240. // remove flake if below player's feet
  241.      if((player == NULL) || (MY_POS.Z < player.Z - 100))
  242.     {
  243.         MY_ACTION = NULL;
  244.     }
  245. }
  246.  
  247.  
  248. // Desc: smoke particle
  249. //      slowly raise (+Z) and drifts (+/- X & Y) while increasing size
  250. //        6/14/00 Doug Poston
  251. //
  252. function particle_smoke()
  253. {
  254.     // just born?
  255.     if(MY_AGE == 0)
  256.     {
  257.         MY_SPEED.X = random(1)-0.5;    // -0.5 to +0.5
  258.         MY_SPEED.Y = random(2)-1;     // -1 to +1
  259.         MY_SPEED.Z = random(1)+1;     // +1 to +2
  260.  
  261.         MY_SIZE = random(25)+25; // 25 to 50 in size
  262.  
  263.           MY_MAP = smoke_map;
  264.         MY_FLARE = ON;
  265.         MY_COLOR.RED = 245;
  266.         MY_COLOR.GREEN = 200;
  267.         MY_COLOR.BLUE = 80;
  268.  
  269.         return;
  270.     }
  271.  
  272.     // increase the size of the smoke particle (up to max)
  273.     if(MY_SIZE < 800)
  274.     {
  275.          MY_SIZE += (1000 - MY_SIZE)*0.1*TIME;
  276.     }
  277.  
  278.     // Remove old particles
  279.     if(MY_AGE >= 35)
  280.     {
  281.           MY_ACTION = NULL;
  282.     }
  283. }
  284.  
  285.  
  286. ////////////////////////////////////////////////////////////////////////
  287.  
  288. // Desc: particles that become transparent about halfway into their life
  289. function particle_fadeout()
  290. {
  291.     if(MY_AGE == 0)
  292.     {
  293.         MY_SPEED.x = random(0.3)-0.15;  // -0.15 - +0.15
  294.         MY_SPEED.y = random(0.3)-0.15;  // -0.15 - +0.15
  295.         MY_SPEED.z = random(0.3)-0.15;  // -0.15 - +0.15
  296.  
  297.         MY_SIZE = 150;
  298.         MY_COLOR.red = 150;
  299.         MY_COLOR.green = 150;
  300.         MY_COLOR.blue = 150;
  301.  
  302.         return;
  303.     }
  304.  
  305.     MY_SIZE += 30 * TIME;
  306.     if(MY_AGE > 2 + random(2)) { MY_TRANSPARENT = ON; }
  307.     if(MY_AGE > 4 + random(2)) { MY_ACTION = NULL; }
  308. }
  309.  
  310. var p2[3];    // array used in particle_line
  311.  
  312. // Desc: produce a vapor trail from p to p2; p and p2 are changed
  313. function particle_line()
  314. {
  315.     vec_sub(p2,p);
  316.     temp = vec_length(p2);
  317.     p2.x = (p2.x * 16) / temp;
  318.     p2.y = (p2.y * 16) / temp;
  319.     p2.z = (p2.z * 16) / temp;
  320.  
  321.     while(temp > 0)
  322.     {
  323.         emit(1,p,particle_fadeout);
  324.         vec_add(p,p2);
  325.         temp -= 16;
  326.     }
  327. }
  328.  
  329.  
  330. BMAP    gbrass_map, <gbrass.pcx>;    // gun 'brass'
  331.  
  332.  
  333. // Desc: gun brass particle (ejected shell)
  334. //            arc from gun
  335. //
  336. function particle_gunBrass()
  337. {
  338.     // just born?
  339.     if(MY_AGE == 0)
  340.     {
  341.         MY_SPEED.X = random(6)-6;    // -3 to 3
  342.         MY_SPEED.Y = random(6)-6;  // -3 to 3
  343.         MY_SPEED.Z = random(3)+8;  // 8 to 11
  344.  
  345.         MY_SIZE = 150;
  346.          MY_MAP = gbrass_map;
  347.          MY_COLOR.RED = 245;
  348.         MY_COLOR.GREEN = 200;
  349.         MY_COLOR.BLUE = 80;
  350.  
  351.         return;
  352.     }
  353.  
  354.     if(MY_SPEED.Z > -16)
  355.     {
  356.         MY_SPEED.Z -= 2 * TIME;
  357.     }
  358.  
  359.     // Remove old particles
  360.     if(MY_AGE >= 35)
  361.     {
  362.           MY_ACTION = NULL;
  363.     }
  364. }
  365.